package org.example.day07;

import java.util.HashMap;
import java.util.Map;

/**
 * 第三章节3.1.10: 方法sleep()不释放锁
 */
public class MyThread8 {
    public void testMethod(Object lock){
        try {
            synchronized (lock){
                System.out.println("begin wait()");
                Thread.sleep(40000); //sleep()不释放锁
                System.out.println("end wait()");
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Object o = new Object();
        Thread8A ta = new Thread8A(o);
        ta.start();
        Thread8B tb = new Thread8B(o);
        tb.start();
    }
}

class Thread8A extends Thread{
    private Object lock;

    public Thread8A(Object lock) {
        this.lock = lock;
    }

    @Override
    public void run() {
        MyThread8 m8 = new MyThread8();
        m8.testMethod(lock);
    }
}

class Thread8B extends Thread{
    private Object lock;

    public Thread8B(Object lock) {
        this.lock = lock;
    }

    @Override
    public void run() {
        MyThread8 m8 = new MyThread8();
        m8.testMethod(lock);
    }
}
